<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 2018/6/20
 * Time: 14:43
 */

namespace Biz\service\activity;

use Biz\model\activity\OutCouponConfig as mOutCouponConfig;
use Biz\module\Classes\adm\OutCoupon as clsAdmOutCoupon;
use Biz\module\Classes\OutCoupon as clsOutCoupon;
/**
 * @deprecated
 */
class OutCoupon
{

    public static function admSearchList($where, $limit)
    {
        $result = clsAdmOutCoupon::getSearchList($where, $limit);

        return $result;
    }

    public static function admChangeStatus($id, $status)
    {
        $result = clsAdmOutCoupon::changeStatus($id, $status);

        return $result;
    }

    public static function admSaveData($data = [], $templates = [])
    {
        try {
            $result = clsAdmOutCoupon::saveData($data, $templates);

            return $result;
        } catch (\Exception $e) {

            throw $e;
        }
    }

    public static function getInfo($id)
    {
        $info = clsOutCoupon::getInfoFromDb($id);

        return $info;
    }

    public static function getInfoByIdMd5($idMd5)
    {
        $info = clsOutCoupon::getInfoByIdMd5FromCache($idMd5);

        if(empty($info)){
            throw new \Exception('活动不存在');
        }

        $data = [
            'title'            => $info['title'],
            'background_color' => $info['background_color'],
            'people_type'      => $info['people_type'],
            'template_data'    => $info['template_data']
        ];

        return $data;
    }

    public static function receive($idMd5, $mobile)
    {
        mOutCouponConfig::action(function () use ($idMd5, $mobile) {
            $result = clsOutCoupon::receive($idMd5, $mobile);

        });

    }


}